package com.example.hyw.szysteam.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;

import com.example.hyw.szysteam.POJO.Practice;
import com.example.hyw.szysteam.POJO.Review;
import com.example.hyw.szysteam.POJO.UserInfo;
import com.example.hyw.szysteam.R;
import com.example.hyw.szysteam.adapter.ReviewAdapter;
import com.example.hyw.szysteam.presenter.MistakeBooksPresenter;
import com.qmuiteam.qmui.widget.QMUITopBar;

import java.util.ArrayList;

/**
 * Created by HYW on 2018/5/24.
 */

public class MistakeBookActivity extends AppCompatActivity {
    QMUITopBar mTopBar;
    ListView listView;
    ArrayList<Review> reviews;
    private MistakeBooksPresenter mistakeBooksPresenter=new MistakeBooksPresenter(MistakeBookActivity.this);
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mistakebook);
        initTopBar();
        mistakeBooksPresenter.getMistakeBooks(UserInfo.getEmail());
    }
    private void initTopBar(){
        mTopBar=findViewById(R.id.topbar);
        mTopBar.setTitle("错题本").setTextColor(getResources().getColor(R.color.myWhite));
        mTopBar.addLeftImageButton(R.drawable.ic_left,R.id.left).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        mTopBar.addRightTextButton("错题练习",R.id.right).setTextColor(getResources().getColor(R.color.myWhite));
        View right=findViewById(R.id.right);
        right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle=new Bundle();
                bundle.putInt("type",3);
                bundle.putParcelableArrayList("list",reviews);
                Intent intent=new Intent(MistakeBookActivity.this, PracticeActivity.class);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }

    public void initListView(ArrayList<Review> reviews){
        this.reviews=reviews;
        listView=findViewById(R.id.listview);
        ReviewAdapter adapter=new ReviewAdapter(MistakeBookActivity.this,R.layout.item_review,reviews);
        listView.setAdapter(adapter);
    }
}
